/**
 * Copyright(c) 2010 Ceno Techonologies Co., Ltd.
 *
 * History:
 *   15-6-18 下午2:39 Created by lyyang
 */
package com.jade.bss.business.bonus;

import java.io.Serializable;
import java.util.Date;
import java.util.Random;
import javax.persistence.*;

/**
 * 红包类
 *
 * @author <a href="mailto:lyyang@ceno.cn">lyyang</a>
 * @version 1.0 15-6-18 下午2:39
 */
@Entity
@Table (name = "BSS_BONUS_INFO")
public class Bonus
        implements Serializable
{
    public static final int TYPE_FIX = 0;
    public static final int TYPE_RANDOM = 1;
    public static final int STATUS_NORMAL = 0;
    public static final int STATUS_PAUSE = 1;
    public static final int STATUS_CLOSE = 5;
    public static final int STATUS_PUBLISH = 9;
    @Id
    @GeneratedValue (generator = "BSS_SEQ_BONUS")
    @SequenceGenerator (name = "BSS_SEQ_BONUS", sequenceName = "BSS_SEQ_BONUS")
    private long id;
    @Column (name = "owner_type")
    private String ownerType;
    @Column (name = "owner_id")
    private String ownerId;
    //发行渠道:微信,微博等等
    private String channel;
    @Column (name = "start_date")
    private Date startDate;
    @Column (name = "end_date")
    private Date endDate;
    private int quantity;
    private int status = STATUS_NORMAL;
    private int type = TYPE_RANDOM;
    //单个红包金额(固定金额类型) 单位:分
    private long bonus;
    //已发放总金额 单位:分
    @Column (name = "total_cost")
    private long totalCost;
    //最多金额(随机类型) 单位:分
    @Column (name = "max_bonus")
    private long maxBonus;
    //最小金额(随机类型) 单位:分
    @Column (name = "min_bonus")
    private long minBonus;
    //中奖概率
    private int percent;
    //发布者名称
    @Column (name = "publisher_name")
    private String publisherName;
    //商户名称
    @Column (name = "shop_name")
    private String shopName;
    //祝福语
    private String wishing;
    //接受者id,微信是openid
    @Column (name = "receiver_id")
    private String receiverId;
    //接受者类型
    @Column (name = "receiver_type")
    private String receiverType;
    //活动名称
    @Column (name = "campaign_name")
    private String campaignName;
    private String remark;
    @Column (name = "share_content")
    private String shareContent;
    @Column (name = "share_url")
    private String shareUrl;
    @Column (name = "share_img_url")
    private String shareImgUrl;
    @Column (name = "logo_url")
    private String logoUrl;
    //总金额
    @Column (name = "total_amount")
    private long totalAmount;
    @Column (name = "create_date", updatable = false)
    private Date createDate;

    public long getTotalAmount()
    {
        return totalAmount;
    }

    public void setTotalAmount(long totalAmount)
    {
        this.totalAmount = totalAmount;
    }

    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    public String getOwnerType()
    {
        return ownerType;
    }

    public void setOwnerType(String ownerType)
    {
        this.ownerType = ownerType;
    }

    public long getTotalCost()
    {
        return totalCost;
    }

    public void setTotalCost(long totalCost)
    {
        this.totalCost = totalCost;
    }

    public String getOwnerId()
    {
        return ownerId;
    }

    public void setOwnerId(String ownerId)
    {
        this.ownerId = ownerId;
    }

    public String getChannel()
    {
        return channel;
    }

    public void setChannel(String channel)
    {
        this.channel = channel;
    }

    public Date getStartDate()
    {
        return startDate;
    }

    public void setStartDate(Date startDate)
    {
        this.startDate = startDate;
    }

    public Date getEndDate()
    {
        return endDate;
    }

    public void setEndDate(Date endDate)
    {
        this.endDate = endDate;
    }

    public int getQuantity()
    {
        return quantity;
    }

    public void setQuantity(int quantity)
    {
        this.quantity = quantity;
    }

    public int getStatus()
    {
        return status;
    }

    public void setStatus(int status)
    {
        this.status = status;
    }

    public int getType()
    {
        return type;
    }

    public void setType(int type)
    {
        this.type = type;
    }

    public long getBonus()
    {
        return bonus;
    }

    public void setBonus(long bonus)
    {
        this.bonus = bonus;
    }

    public long getMaxBonus()
    {
        return maxBonus;
    }

    public void setMaxBonus(long maxBonus)
    {
        this.maxBonus = maxBonus;
    }

    public long getMinBonus()
    {
        return minBonus;
    }

    public void setMinBonus(long minBonus)
    {
        this.minBonus = minBonus;
    }

    public int getPercent()
    {
        return percent;
    }

    public void setPercent(int percent)
    {
        this.percent = percent;
    }

    public String getPublisherName()
    {
        return publisherName;
    }

    public void setPublisherName(String publisherName)
    {
        this.publisherName = publisherName;
    }

    public String getShopName()
    {
        return shopName;
    }

    public void setShopName(String shopName)
    {
        this.shopName = shopName;
    }

    public String getWishing()
    {
        return wishing;
    }

    public void setWishing(String wishing)
    {
        this.wishing = wishing;
    }

    public String getReceiverId()
    {
        return receiverId;
    }

    public void setReceiverId(String receiverId)
    {
        this.receiverId = receiverId;
    }

    public String getReceiverType()
    {
        return receiverType;
    }

    public void setReceiverType(String receiverType)
    {
        this.receiverType = receiverType;
    }

    public String getCampaignName()
    {
        return campaignName;
    }

    public void setCampaignName(String campaignName)
    {
        this.campaignName = campaignName;
    }

    public String getRemark()
    {
        return remark;
    }

    public void setRemark(String remark)
    {
        this.remark = remark;
    }

    public String getShareContent()
    {
        return shareContent;
    }

    public void setShareContent(String shareContent)
    {
        this.shareContent = shareContent;
    }

    public String getShareUrl()
    {
        return shareUrl;
    }

    public void setShareUrl(String shareUrl)
    {
        this.shareUrl = shareUrl;
    }

    public String getShareImgUrl()
    {
        return shareImgUrl;
    }

    public void setShareImgUrl(String shareImgUrl)
    {
        this.shareImgUrl = shareImgUrl;
    }

    public String getLogoUrl()
    {
        return logoUrl;
    }

    public void setLogoUrl(String logoUrl)
    {
        this.logoUrl = logoUrl;
    }

    public boolean isLucky()
    {
        if (percent >= 100) {
            return true;
        }
        Random random = new Random(System.currentTimeMillis());
        return random.nextInt(99) < percent;
    }

    public Date getCreateDate()
    {
        return createDate;
    }

    public void setCreateDate(Date createDate)
    {
        this.createDate = createDate;
    }
}
